package com.laivi.basic.module.syncdata;

import java.io.File;

import com.laivi.basic.model.file.reader.CsvReader;
import com.laivi.basic.model.syncdata.DestDatabase;
import com.laivi.basic.module.sql.DBDao;
import com.laivi.basic.module.sql.SqlDao;

public class CSVToDBTask extends Task {
	private File srcFile;
	private DestDatabase dest;
	private DBDao destDao;

	public CSVToDBTask() {
	}
	
	public CSVToDBTask(String name,long period,String path,DestDatabase dest){
		super(name,period);
		this.srcFile=new File(path);
		this.dest = dest;
		this.destDao=new SqlDao(dest);
	}

	@Override
	public void execute() throws Exception {
		if(srcFile!=null && srcFile.exists()){
			CsvReader csv=new CsvReader(this.srcFile);
			destDao.add(dest.getTable(), csv.read(dest.getFields()));
		}
	}

}
